import { ref } from 'vue'
import { useMapStore } from '@/stores/map.js'
import { storeToRefs } from 'pinia'
// 引入点查询de中地接口
import { Point } from '@/Utils/Point.js'
import { useDialogEvents } from '@/stores/dialogEvents.js'
import { useDialog } from '@/stores/dialogSwitch.js'

const { map } = storeToRefs(useMapStore())

// 定义获取点击的 事件数据
const { changeEvents } = storeToRefs(useDialogEvents())
// 事件更新popup控制开关
const { changeEventDialogVisible, addEventDialogVisible } = storeToRefs(useDialog())
export const changeEvent = () => {
  //把事件更新的控制器关掉
  var change = map.value.once('click', (e) => {
    // 2. 点击map获取坐标
    let changeEventPosition = e.coordinate
    let service = {
      name: 'guanggu',
      layerId: 2,
    }
    // 3. 查询点击坐标的事件
    Point.query({
      position: changeEventPosition,
      service,
      callback: handleQuery,
    })
  })

  function handleQuery(res) {
    if (res) {
      changeEvents.value = res[0].values_.values_
      changeEvents.value.id_ = res[0].id_
      changeEventDialogVisible.value = true
    }
  }
}
